<!-- 列表 -->
<template>
  <div class="list">
    <!-- 列表数据 -->
    <div class="ulist">
      <!-- 筛选头部 -->
      <div class="screen">
        <input-screen :placeholder="placeholder" @fromChild="getChildinput"></input-screen>
        <!-- <Select @fromChild="getChilddpthree"> </Select> -->
        <date-picker-two @fromChild="getChilddpone"></date-picker-two>
        <el-button type="primary" round @click="query" style="margin-left:2%;">查询</el-button>
        <el-button type="success" round @click="q_data" style="margin-left:2%;">全部数据</el-button>
      </div>
      <!-- 列表数据 -->
      <div class="list_data">
        <table-list :tableData="tableData" :listHeader="listHeader" @operate="operate" :type="type"></table-list>
        <!-- 分页 -->
        <div class="paging">
          <paging-list @Listdata="getChilddptwo" :addNum="addNum"></paging-list>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import inputScreen from "../../components/screen/input";
import TableList from "../../components/List/TableList";
import PagingList from "../../components/List/PagingList";
import DatePickerTwo from "../../components/screen/DatePickerTwo";
export default {
  data() {
    return {
      placeholder: "请输入用户昵称", //input框中的placehould
      content: "", //input收入值
      value: "", //单时间日期
      starttime: "", //搜索起始时间
      endtime: "", //搜索结束时间
      Bnumber: 10, //每页条数
      Pnumber: 1, //当前页数
      addNum: 0, //总共多少条数
      selectname: "", //下拉列表内容
      tableData: [], //列表数据
      listHeader: [], //列表的渲染部分
      datas: {}, //列表操作返回的数据
      type: "orderlist" //列表标识
    };
  },
  components: {
    TableList,
    PagingList,
    inputScreen,
    DatePickerTwo
    // DatePickerOne
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.userAdminList();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {
    let header_name = [
      "订单号",
      "订单金额",
      "创建时间",
      "支付状态",
      "支付方式",
      "支付时间",
      "是否删除",
      "用户昵称",
      "课程名称"
    ]; //列表头部
    let list_content = [
      "order_sn",
      "money",
      "create_time",
      "pay_status",
      "pay_type",
      "pay_time",
      "is_del",
      "nickName",
      "course_name"
    ]; //列表渲染内容字段
    for (let key in this.tableData[0]) {
      list_content.push(key);
    }
    for (let i = 0; i < header_name.length; i++) {
      let obj = {
        label: header_name[i],
        prop: list_content[i]
      };
      this.listHeader.push(obj);
    }
    console.log(this.listHeader);
  },
  methods: {
    //获取input搜索值
    getChildinput(v) {
        console.log(v)
      if (v != null) {
        this.content = v;
      } else {
        this.content = "";
      }
    },
    //获取时间
    getChilddpone(v) {
      if (v != null) {
        this.starttime = v[0];
        this.endtime = v[1];
      } else {
        this.starttime = "";
        this.endtime = "";
      }
    },
    //获取分页信息
    getChilddptwo(e) {
      this.Pnumber = e.Pnumber;
      this.Bnumber = e.Bnumber;
    },
    //获取下拉数据
    // getChilddpthree(e){
    //     this.selectname = e;
    // },
    //点击查询
    query() {
      this.$api
        .orderList({
          token: this.publick.token(),
          page: this.Pnumber,
          limit: this.Bnumber,
          key: this.content,
          starttime: this.starttime,
          endtime: this.endtime
        })
        .then(res => {
          console.log(res);
          this.tableData = res.data.data;
          this.addNum = res.data.total;
        })
        .catch(res => {
          console.log(res);
        });
    },
    // 获取全部数据
    q_data() {
      this.userAdminList();
    },
    //获取列表操作的数据
    operate(e) {
      this.datas = e;
      if (this.datas.type == "look") {
        //    跳转查看页面
      } else if (this.datas.type == "delect") {
        //删除用户
        alert("delect");
      }
    },
    userAdminList() {
      //获取用户列表
      this.$api
        .orderList({
          token: this.publick.token(),
          page: this.Pnumber,
          limit: this.Bnumber
        })
        .then(res => {
          console.log(res);
          this.tableData = res.data.data;
          this.addNum = res.data.total;
        })
        .catch(res => {
          console.log(res);
        });
    }
  },
  watch: {
    Bnumber(newval) {
      if (newval) {
        this.userAdminList();
      }
    },
    Pnumber(newval) {
      if (newval) {
        this.userAdminList();
      }
    }
  }
};
</script>
<style scoped>
/* @import url(); 引入css类 */
.list {
  width: 100%;
  height: 89vh;
  background: #fff;
  overflow-y: auto;
}
.ulist {
  background: #fff;
  width: 98%;
  margin: auto;
  margin-top: 2.5vh;
}
.screen {
  display: flex;
  height: 8vh;
  justify-content: flex-start;
  align-items: center;
}
.list_data {
  width: 98%;
  margin: auto;
  margin-top: 4vh;
}
.paging {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  margin-top: 4vh;
  padding-bottom: 2vh;
}
</style>